package cn.valorin.event;

import static cn.valorin.configuration.languagefile.MessageSender.sm;

import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

import cn.valorin.data.Data;
import cn.valorin.item.BeanSeed;
import cn.valorin.item.RawBean;
import cn.valorin.item.RawRice;
import cn.valorin.item.RiceSeed;
import cn.valorin.via.Via;

public class HarvestEvent implements Listener {
	@SuppressWarnings("deprecation")
	@EventHandler
	public void harvestBean(BlockBreakEvent e) { //收获豆子
		Player player = e.getPlayer();
	  	Block block = e.getBlock();
  	    if (!block.getType().equals(Via.crops)) { return; }
	  	if (Data.isPlant(
	  			block.getWorld().getName(),
	  			block.getX(),
	  			block.getY(),
	  			block.getZ(),
	  			0)) {
	  		Data.removePlant(
	  				block.getWorld().getName(),
		  			block.getX(),
		  			block.getY(),
		  			block.getZ(),
		  			0);
  	    	e.setDropItems(false);
	  	    if (block.getData() == 7) {
	  	    	block.getWorld().dropItem(block.getLocation(), RawBean.get(player));
	  	    	block.getWorld().dropItem(block.getLocation(), RawBean.get(player));
	  	    	sm("&a你收获了豆子",player);
	  	    } else {
	  	    	block.getWorld().dropItem(block.getLocation(), BeanSeed.get(player));
	  	    }
	  	}
	}
	
	@SuppressWarnings("deprecation")
	@EventHandler
	public void harvestRice(BlockBreakEvent e) { //收获糯米
		Player player = e.getPlayer();
	  	Block block = e.getBlock();
	  	if (!block.getType().equals(Via.crops)) { return; }
	  	if (Data.isPlant(
	  			block.getWorld().getName(),
	  			block.getX(),
	  			block.getY(),
	  			block.getZ(),
	  			1)) {
	  		Data.removePlant(
	  				block.getWorld().getName(),
		  			block.getX(),
		  			block.getY(),
		  			block.getZ(),
		  			1);
  	    	e.setDropItems(false);
	  	    if (block.getData() == 7) {
	  	    	block.getWorld().dropItem(block.getLocation(), RawRice.get(player));
	  	    	block.getWorld().dropItem(block.getLocation(), RawRice.get(player));
	  	    	sm("&a你收获了糯米",player);
	  	    } else {
	  	    	block.getWorld().dropItem(block.getLocation(), RiceSeed.get(player));
	  	    }
	  	}
	}
}
